package ph.com.gs3.formalistics.service;

import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;

public class ServiceQueue {

	private List<QueueableService> serviceQueue;
	private List<Bundle> serviceQueueExtras;
	private Context context;

	public ServiceQueue(Context context) {
		this.context = context;
		serviceQueue = new ArrayList<>();
		serviceQueueExtras = new ArrayList<>();
	}

	public void add(QueueableService service, Bundle extras) {
		serviceQueue.add(service);
		serviceQueueExtras.add(extras);
	}

	public void executeQueue() {

		for (int i = 0; i < serviceQueue.size(); i++) {
			startService(serviceQueue.get(i), serviceQueueExtras.get(i));
		}

	}

	protected void startService(QueueableService serviceClass, Bundle extras) {

		Intent intent = new Intent(context, serviceClass.getClass());
		intent.putExtras(extras);
		context.startService(intent);		

	}

}
